import request from '@/utils/request'
import { tansParams } from "@/utils/ruoyi";

// 登录方法
export function login(username, password) {
  const formData = new FormData();
  formData.append('user_name', username);
  formData.append('password', password);
  formData.append('app_id', process.env.VUE_APP_APP_ID);
  formData.append('app_secret', process.env.VUE_APP_APP_SECRET);
  formData.append('grant_type', 'app_auth');
  formData.append('scope', 'open_api');

  return request({
    url: '/dp-server/authority-server/oauth/token',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取用户详细信息
export function getInfo() {
  return request({
    url: '/dp-server/server-system/user/info',
    method: 'get'
  })
}

// 退出方法
export function logout() {
  return request({
    url: '/dp-server/authority-server/login/logout',
    method: 'post'
  })
}

// 获取验证码
export function getCodeImg() {
  return request({
    url: '/captchaImage',
    headers: {
      isToken: false
    },
    method: 'get',
    timeout: 20000
  })
}

// 刷新Token
export function refreshToken(refresh_token) {
  const data = {
    grant_type: 'refresh_token',
    refresh_token: refresh_token,
    app_id: process.env.VUE_APP_APP_ID,
    app_secret: process.env.VUE_APP_APP_SECRET
  }
  return request({
    url: '/dp-server/authority-server/oauth/token',
    headers: {
      'Content-Type': 'application/json'
    },
    method: 'post',
    data: data
  })
}
